package com.charles.springcloud.controller;

import com.charles.common.CommonResult;
import com.charles.springcloud.entity.Payment;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;

/**
 * @Author: 风中灵劲草
 * @Date: 2021/07/20/15:13
 * @Description:
 */
@RestController
@Slf4j
@RequestMapping("/consumer")
public class OrderController {

//    public static final String PAYMENT_URL = "http://localhost:8001/payment";  //单机版
    public static final String PAYMENT_URL = "http://cloud-payment-service";   //集群版，"http://" + 微服务名
    @Autowired
    RestTemplate restTemplate;

    @GetMapping("/payment/create")
    public CommonResult<Payment> create(@RequestBody Payment payment){
        return restTemplate.postForObject(PAYMENT_URL + "/create" , payment , CommonResult.class);
    }
    @GetMapping("/payment/getPayment/{id}")
    public CommonResult<Payment> getPaymentById(@PathVariable("id") Long id){
        return restTemplate.getForObject(PAYMENT_URL + "/getPayment/" + id , CommonResult.class);
    }
}
